package com.stx.blog.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.stx.blog.dao.CategoryDao;
import com.stx.blog.entity.CategoryEntity;
import com.stx.blog.service.CategoryService;
import com.stx.blog.vo.CategoryVo;

public class CategoryServiceImpl implements CategoryService{
	private CategoryDao dao = null;

	public List<CategoryVo> list(CategoryVo criteria) {

		List<CategoryVo> voList = new ArrayList<CategoryVo>();

		List<CategoryEntity> entityList = dao.list(criteria);

		for (CategoryEntity entity : entityList) {

			CategoryVo vo = new CategoryVo();
			
			BeanUtils.copyProperties(entity, vo);

			voList.add(vo);

		}

		return voList;
	}

	public void delCategory(Integer id) {

		dao.delCategory(id);

	}

	
	public void addCategory(CategoryVo category) {

		dao.addCategory(category);

	}

	public CategoryVo findCategoryForUpdate(Integer id) {

		CategoryVo categoryVo = new CategoryVo();

		CategoryEntity categoryEntity = dao.findCategoryById(id);

		BeanUtils.copyProperties(categoryEntity, categoryVo);

		return categoryVo;
	}

	public void updateCategory(CategoryVo category) {

		dao.updateCategory(category);

	}

	public void setDao(CategoryDao dao) {
		this.dao = dao;
	}



}
